<template>
    <div>
      <div>
        <el-input style="width: 200px; margin: 0 8px; " placeholder="查寻模块" v-model="module"></el-input>
        <el-button type="primary" @click="load(1)">查询</el-button>
        <el-button type="warning" @click="reset">重置</el-button>
      </div>
      <div style="margin: 10px 0;">
        <el-button type="danger" plain @click="delBatch">批量删除</el-button>
      </div>
      <el-table v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)" :data="logs" stripe
        :header-cell-style="{ backgroundColor: 'aliceblue', color: '#333' }" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column label="序号" type="index" :index="indexMethod"></el-table-column>
        <el-table-column label="操作模块" prop="module" align="center"></el-table-column>
        <el-table-column label="操作类型" prop="type" align="center"></el-table-column>
        <el-table-column label="操作人" prop="user" align="center"></el-table-column>
        <el-table-column label="操作时间" prop="time" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template v-slot="scope">
            <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin: 10px 0;">
        <el-pagination background layout="total,sizes, prev, pager, next" :total="total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" :current-page.sync="currentPage2" :page-sizes="[5, 10, 20]"
          :page-size="pageSize">
        </el-pagination>
      </div>
    </div>
  </template>

<script>
export default {
   name: 'UserView',
   data() {
     return {
        logs:[],
        pageSize:10,
        pageNum:1,
        module:'',
        total:'',
        dialogVisible: false,
        ids:[],
        index:'',
        loading:false,
     }
   },
   created(){
    this.load()
   },

   mounted() {
    
   },
   methods: {
     indexMethod(index) {
       return (this.pageNum - 1) * this.pageSize + index + 1;
     },
    delBatch(){
      if(!this.ids.length){
        this.$message.warning('请选择数据')
        return
      }
      this.$confirm('您确认删除吗','确认',{type:"warning"}).then(response=>{
        this.$request.delete('/logs/delete',{data:this.ids}).then(res=>{
          console.log(response)
          if(res.code=='1'){
            this.$message.success('操作成功')
            this.load(1)
          }else{
            this.$message.error(res.msg)
          }
        })
   
      }).catch(()=>{})
    },
    handleSelectionChange(rows){
      this.ids=rows.map(v=>v.id)
    },
    del(id){
      this.$confirm('您确认删除吗','确认',{type:"warning"}).then(response=>{
        this.$request.delete('/logs/delete/'+id).then(res=>{
          console.log(response)
          if(res.code=='1'){
            this.$message.success('操作成功')
            this.load(1)
          }else{
            this.$message.error(res.msg)
          }
        })
   
      }).catch(()=>{})
    },
    reset(){
      this.module=" "
      this.load()
    },
    load(pageNum){
      if(pageNum)this.pageNum=pageNum
      this.$request.get('/logs/selectByPage',{
        params:{
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          module:this.module,
        }
      }).then(res=>{
        this.logs=res.data.records
        this.total=res.data.total
      })
    },
     handleCurrentChange(pageNum){
      this.pageNum=pageNum
      this.load(pageNum)
     },
     handleSizeChange(pageSize){
      this.pageSize=pageSize;
      this.load()
     },
   }
};
</script>
<style lang='' scoped>
</style>